<template>
  <div class="page">
    <!-- 我的收藏 -->
    <div class="collect">
      <h3>
        <span class="left">
          <i class="icon iconfont icon-xihuan1"></i>
          <span>我收藏的住宿</span>
        </span>
        <i class="jump iconfont icon-fanhui"></i>
        <!-- @click="routerJump('push', 'Community/communityHome')" -->
      </h3>
      <div class="concernInfo">
        <div
          v-if="!saveAccommodations.accommodationTotal"
          style="color: #999; font-weight: 500; font-size: 18px; letter-spacing: 1px"
        >
          <el-empty :image-size="100" description="暂无收藏."></el-empty>
        </div>
        <el-row v-else :gutter="20">
          <el-col :span="24">
            <div class="hotels">
              <template v-if="saveAccommodations && saveAccommodations.accommodationTotal">
                <div
                  class="hotels-item"
                  v-for="item in saveAccommodations.accommodationLists"
                  :key="item.id"
                  @click="selectAccommodation(item)"
                >
                  <img :src="item.images[0]" alt="" />
                  <div class="info">
                    <div class="name">{{ item.name }}</div>
                    <div class="price">
                      <div>
                        <span class="f">{{ item.charge }}</span
                        >起
                      </div>
                      <div>
                        <span class="s">{{ item.view_counts }}</span
                        >热度
                      </div>
                    </div>
                  </div>
                </div>
                <!-- <div
                  class="hotels-item"
                  v-show="saveAccommodations.accommodationTotal % 3 == 2"
                ></div> -->
              </template>

              <template v-else>
                <div class="hotels-item">
                  <img src="@/assets/images/hanting_hotel.jpg" alt="" />
                  <div class="info">
                    <div class="name">xxxx</div>
                    <div class="price">
                      <div><span class="f">￥180</span>起</div>
                      <div><span class="s">1993</span>点评</div>
                    </div>
                  </div>
                </div>
              </template>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 分页器 -->
      <ele-pagination
        :defaultPageSize="3"
        :totalCount="saveAccommodations.accommodationTotal"
        @paginationChange="reqSaveAccommodations"
      ></ele-pagination>
    </div>

    <!-- 我的预约-->
    <div class="publish">
      <h3>
        <span class="left">
          <i class="icon iconfont icon-chuangzuo"></i>
          <span>我的预约</span>
        </span>
        <i class="jump iconfont icon-fanhui"></i>
        <!-- @click="routerJump('push', 'Community/communityHome')" -->
      </h3>
      <div class="concernInfo">
        <div
          v-if="!reservationAccommodations.accommodationTotal"
          style="color: #999; font-weight: 500; font-size: 18px; letter-spacing: 1px"
        >
          <el-empty :image-size="100" description="暂无收藏."></el-empty>
        </div>
        <el-row v-else :gutter="20">
          <el-col :span="24">
            <div class="hotels">
              <template v-if="reservationAccommodations && saveAccommodations.accommodationTotal">
                <div
                  class="hotels-item"
                  v-for="item in reservationAccommodations.accommodationLists"
                  :key="item.id"
                >
                  <el-tag size="large" type="success">预约成功</el-tag>
                  <!-- @click="selectAccommodation(item)" -->
                  <img :src="item.images[0]" alt="" />
                  <div class="info">
                    <div class="name">{{ item.name }}</div>
                    <div class="price">
                      <div>
                        开始时间：
                        <span class="f">
                          {{ formatDate(item.start_time, true).toString().slice(0, 10) }}</span
                        >
                      </div>
                      <div>
                        结束时间：
                        <span class="s">{{
                          formatDate(item.end_time, true).toString().slice(0, 10)
                        }}</span>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- <div
                  class="hotels-item"
                  v-show="reservationAccommodations.accommodationTotal % 3 == 2"
                ></div> -->
              </template>

              <template v-else>
                <div class="hotels-item">
                  <img src="@/assets/images/hanting_hotel.jpg" alt="" />
                  <div class="info">
                    <div class="name">xxxx</div>
                    <div class="price">
                      <div><span class="f">￥180</span>起</div>
                      <div><span class="s">1993</span>点评</div>
                    </div>
                  </div>
                </div>
              </template>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 分页器 -->
      <ele-pagination
        :defaultPageSize="3"
        :totalCount="reservationAccommodations.accommodationTotal"
        @paginationChange="reqGetReservation"
      ></ele-pagination>
    </div>
  </div>
</template>

<script setup lang="ts">
import useRouterJump from "@/hooks/useRouterJump"
import useAccommodationStore from "@/store/main/acccommodation/acccommodation"

import { localCache } from "@/utils/cacheData"
import { storeToRefs } from "pinia"
import { onMounted } from "vue"
import { formatDate } from "@/utils/format"

const { routerJump } = useRouterJump()

const accommodationStore = useAccommodationStore()
const { saveAccommodations, reservationAccommodations } = storeToRefs(accommodationStore)

// 获取用户收藏
function reqSaveAccommodations(limit?: number, offset?: number) {
  accommodationStore.getSaveAccommodation(limit, offset)
}

// 获取用户预约
function reqGetReservation(limit?: number, offset?: number) {
  accommodationStore.getReservation(limit, offset)
}

/* 去信息页面 */
function selectAccommodation(item) {
  localCache.setCache("accommodationInfo", item)
  routerJump("push", "AccommodationParticular")
}

onMounted(() => {
  reqSaveAccommodations()
  reqGetReservation()
})
</script>

<style lang="less" scoped>
.page {
  display: flex;
  flex-direction: column;

  .publish,
  .collect,
  .support,
  .opinion {
    // width: 620px;
    // height: 260px;
    background: #fff;
    margin-bottom: 40px;
    padding: 0 10px 50px 10px;
    border-bottom: 1px solid #ddd;

    h3 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 18px;
      font-weight: 500;
      letter-spacing: 1px;
      .left {
        display: flex;
        align-items: center;
        .icon {
          font-size: 24px;
          color: #999;
          margin-right: 6px;
        }
      }

      .jump {
        cursor: pointer;
        float: right;
        color: rgba(153, 153, 153, 0.65);
        line-height: 24px;
        font-size: 18px;
        transition: all 0.5s;
        &:hover {
          color: #666;
        }
      }
    }

    .concernInfo {
      // height: 100px;
      // background-color: red;
      margin-top: 20px auto 0 auto;
      .defaultImg {
        width: 40%;
        margin: 0 auto;
        img {
          width: 100%;
        }
      }
      .el-row {
        position: relative;
        border-radius: 12px;
        margin-bottom: 20px;
        padding: 0;
        .el-col {
          display: flex;
        }

        .hotels {
          margin: 0px auto;
          display: flex;

          flex-wrap: wrap;
          justify-content: center;
          // justify-content: center;
          // align-items: center;
          .hotels-item {
            width: 400px;
            height: 350px;
            margin: 20px 20px 28px 20px;
            border-radius: 20px;

            img {
              width: 400px;
              height: 300px;
              border-radius: 20px;
              cursor: pointer;
              margin-bottom: 10px;
              transition: all 0.25s;
              &:hover {
                box-shadow: 5px 5px 5px 5px rgb(69, 88, 115);
              }
            }

            .info {
              width: 400px;
              margin-top: 12px;
              .name {
                font-size: 20px;
                font-weight: bold;
                overflow: hidden;
                white-space: nowrap; /* 不换行 */
                text-overflow: ellipsis; /* 显示省略号 */
              }
              .price {
                display: flex;
                justify-content: space-between;
                margin-top: 8px;
                .f {
                  color: red;
                  font-size: 16px;
                  margin-right: 10px;
                }
                .s {
                  margin-right: 10px;
                  font-size: 16px;
                  color: rgb(69, 88, 115);
                }
              }
            }
          }
        }
      }
    }
  }

  .publish {
    .concernInfo {
      .hotels {
        .hotels-item {
          position: relative;
          .info {
            .price {
              .s {
                color: red !important;
              }
            }
          }
          .el-tag {
            position: absolute;
            top: 20px;
            left: 20px;
          }
        }
      }
    }
  }

  .opinion {
    .header {
      font-size: 18px;
      font-weight: 500;
      letter-spacing: 1px;
      display: flex;
      justify-content: space-between;
      .reply {
        cursor: pointer;
        width: 22px;
        height: 22px;
      }
    }

    .concernInfo {
      .content {
        h3 {
          letter-spacing: 0.5px;
        }
        .footer {
          margin-top: 10px;
          .createdTime {
            color: #999999;
          }
          .delete {
            cursor: pointer;
            float: right;
            width: 24px;
            height: 24px;
          }
        }
      }
    }
  }
}
</style>

<style scoped>
.el-card {
  --el-card-padding: 0px;
}
</style>
